package com.chixing.work;

import com.chixing.controller.WebSocketProcess;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.time.LocalDateTime;
import java.util.Map;

@Component
public class NotificationMessageConsumer {
    @Autowired
    private WebSocketProcess webSocketProcess;

    @RabbitListener(queues = "ticket_purchased_queue")
    public void handleTicketPurchased(Map<String, Object> message) throws IOException {
        Integer userId = (Integer) message.get("userId");
        String content = (String) message.get("message");
        LocalDateTime timestamp = (LocalDateTime) message.get("timestamp");

        // 这里调用实际的消息推送方法，比如WebSocket、短信或邮件
        System.out.println("发送给用户 " + userId + " 的消息: " + content + " 时间: " + timestamp);
        webSocketProcess.sendMessage(Long.valueOf(userId), content);
        // 实际项目中这里应该调用真正的消息推送服务
    }

    @RabbitListener(queues = "ticket_refunded_queue")
    public void handleTicketRefunded(Map<String, Object> message) throws IOException {
        Integer userId = (Integer) message.get("userId");
        String content = (String) message.get("message");
        LocalDateTime timestamp = (LocalDateTime) message.get("timestamp");

        // 这里调用实际的消息推送方法

        System.out.println("发送给用户 " + userId + " 的消息: " + content + " 时间: " + timestamp);
        webSocketProcess.sendMessage(Long.valueOf(userId), content);
        // 实际项目中这里应该调用真正的消息推送服务
    }
}
